package com.ygo.feihua;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.QueryListener;
import com.ygo.feihua.BmobTable.Kadian;
import com.ygo.feihua.view.Advertisements;
import java.util.List;
import org.json.JSONArray;


public class KadianXiangxi extends Activity
{
	private LinearLayout llAdvertiseBoard;
	LayoutInflater inflater;
	TextView kd_name,kd_user,kd_phone,kd_cs,kd_dz,kd_jie;
	TextView kd_dx;
	Double jd=0.0;
	Double wd=0.0;
	Gongju gj;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		// TODO: Implement this method
		super.onCreate(savedInstanceState);
		setContentView(R.layout.kadian_xiangxi);
		
		Intent intent=this.getIntent();
		String id=intent.getStringExtra("id");
		gj=Gongju.getdx(KadianXiangxi.this);
		inflater = LayoutInflater.from(KadianXiangxi.this);
		initViews(id);
		
	}
	
	private void initViews(final String id) {
		llAdvertiseBoard = (LinearLayout)findViewById(R.id.llAdvertiseBoard);

		kd_user=(TextView) findViewById(R.id.kd_user);
		kd_phone=(TextView) findViewById(R.id.kd_phone);
		kd_cs=(TextView) findViewById(R.id.kd_cs);
		kd_dz=(TextView) findViewById(R.id.kd_dz);
		kd_name=(TextView) findViewById(R.id.kd_name);
		kd_jie=(TextView) findViewById(R.id.kd_jie);
		kd_dx=(TextView) findViewById(R.id.kd_dx);
		
		kd_dx.setOnClickListener(new OnClickListener(){

				@Override
				public void onClick(View p1)
				{
					if(jd==0.0||wd==0.0){
						gj.show("请等待数据加载完毕");
					}else{
						Intent intent=new Intent(KadianXiangxi.this,KadianDitu.class);
						intent.putExtra("dk",2);
						intent.putExtra("jd",jd);
						intent.putExtra("wd",wd);
						startActivity(intent);
					}
					// TODO: Implement this method
				}
			});
		
		
		
		BmobQuery<Kadian> kd=new BmobQuery<Kadian>();
		kd.getObject(id, new QueryListener<Kadian>(){

				@Override
				public void done(Kadian p1, BmobException p2)
				{
					if(p2==null){
						kd_name.setText(p1.getKd_name());
						kd_user.setText("店主:"+p1.getKd_user());
						kd_phone.setText("电话:"+p1.getKd_phone());
						kd_cs.setText("城市:"+p1.getKd_cs());
						kd_dz.setText("地址:"+p1.getKd_dz());
						kd_jie.setText(p1.getKd_jie());
						jd=p1.getKd_jd();
						wd=p1.getKd_wd();
						//简介图
						llAdvertiseBoard.addView(new Advertisements(KadianXiangxi.this, true,  3000,2).initView((List<Object>)p1.getKdjt()));
					}
					// TODO: Implement this method
				}
			});
}

		
	
}
